package com.titan.demo.camel.sample.eip.split.SplitAggregationStrategy;

import java.util.List;

import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;

import com.titan.demo.camel.utils.RunCamel;

public class Test01 {
	public static void main(String[] args) {
        try {
        	RouteBuilder route = createRouteBuilder();
        	createRunCamel().run(route);
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	
	
	private static RunCamel createRunCamel() {
		return new RunCamel() {
			protected void execute(CamelContext context,
					ProducerTemplate producer, ConsumerTemplate consumer)
					throws Exception {
				producer.sendBody("direct:in", "Hello World!");
			}
		};
	}
	
	private static RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("direct:in")
                .bean(TttBean.class, "start")   // 初始化数据
                .split(body(List.class), new MyAggregationStrategy())
                .bean(TttBean.class, "processOneLi")
                .end()
                .split(body(List.class))
                .bean(TttBean.class, "processOne")
                .bean(TttBean.class, "end")
                ;
            }
        };
    }
}
